﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;

namespace THL.DataAccess
{
    public class DataProvider
    {
        private static IDataProvider m_Instance;
        private static Object m_Lock = new Object();

        static DataProvider()
        {
            GetProvider();
        }
        private static void GetProvider()
        {
            try
            {
                ConnectionStringSettingsCollection connectionCollection = ConfigurationManager.ConnectionStrings;
                String providerName = connectionCollection[1].Name;
                m_Instance = (IDataProvider)Activator.CreateInstance(
                    Type.GetType(String.Format("THL.DataAccess.{0}.DataProvider, THL.DataAccess", providerName), false, true)
                    );
            }
            catch
            {
                throw;
            }
        }
        public static IDataProvider Instance
        {
            get
            {
                if (m_Instance == null)
                {
                    lock (m_Lock)
                    {
                        if (m_Instance == null) GetProvider();
                    }
                }
                return m_Instance;
            }
        }
        public static void ResetDataProvider()
        {
            m_Instance = null;
        }
    }
}
